package cn.newhopedairy.gateway.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.reactive.EnableWebFluxSecurity;
import org.springframework.security.config.web.server.ServerHttpSecurity;
import org.springframework.security.web.server.SecurityWebFilterChain;

/**
 * @author Neo.Li
 * @date 2021-01-2215:39
 */
@Configuration
@EnableWebFluxSecurity
public class WebSecurityConfig {
    private static final String[] excludedAuthPages = {
            "/swagger-ui/**",
            "/swagger-resources/**",
            "/*/v3/api-docs"
    };

    @Bean
    public SecurityWebFilterChain springSecurityFilterChain(ServerHttpSecurity http) throws Exception {
        http
                .csrf().disable()
                .authorizeExchange()
                .pathMatchers(excludedAuthPages).permitAll()
                .anyExchange().authenticated()
                .and()
                .oauth2ResourceServer()
                .jwt();
        return http.build();
    }
}
